<?php

/* * 
 * 数据入库后更新处理类
 * Some rights reserved：abc3210.com
 * Contact email:admin@abc3210.com
 */
class content_update {

    public $modelid;
    public $fields;
    public $data;
    public $Action;
    public $id;

    function __construct($modelid , &$Action = "", $id) {
        $this->modelid = $modelid;
        $this->fields = F("Model_field_" . $modelid);
        $this->id = $id;
        $this->Action = $Action;
    }
    
    /**
     * 错误提示
     */
    public function error($message, $jumpUrl = '', $ajax = false) {
        $this->Action->error($message, $jumpUrl, $ajax);
    }

    function update($data) {
        $info = array();
        $this->data = $data;
        foreach ($data as $field => $value) {
            if (!isset($this->fields[$field]))
                continue;
            $func = $this->fields[$field]['formtype'];
            //配置
            $setting = unserialize($this->fields[$field]['setting']);
            
            $value = method_exists($this, $func) ? $this->$func($field, $value) : $value;
            
             //字段扩展，可以对字段内容进行再次处理，类似ECMS字段处理函数
            if($setting['backstagefun'] || $setting['frontfun']){
                load("@.treatfun");
               $backstagefun = explode("###",$setting['backstagefun']);
               $usfun = $backstagefun[0];
               $usparam = $backstagefun[1];
                //前后台
                if(isadmin == 1){
                     //检查方法是否存在
                    if(function_exists($usfun)){
                        //判断是入库执行类型
                        if( (int)$setting['backstagefun_type'] >= 2 ){
                            //调用自定义函数，参数传入：模型id，信息ID，字段内容，字段名，操作类型，附加参数
                            // 例子 demo($modelid ,$value , $id, $field ,$action ,$param){}
                            @$value = call_user_func($usfun, $this->modelid ,$this->id ,$value ,$field ,ACTION_NAME,$usparam);
                        }
                    }
                }else{
                    //前台投稿处理自定义函数处理
                }
            }
            
            $info[$field] = $value;
        }
    }

}?>